/**
 * 项目基础数据仓库
 */
import _config from "../../../../config/config"
const state = {
	user: {},
	dq:[],
	areas:[],
	campus:[],
	villsnb:[],//南白地区的社区
}

const mutations = {
	setUser(state, user) {
		state.user = user;
	},
	setdq(state, dq) {		
		state.dq = dq;
	},
	setAreas(state, areas) {		
		state.areas = areas;
	},
	setCampus(state, campus) {
		state.campus = campus;
	},
	setVillsnb(state, villsnb) {
		state.villsnb = villsnb;
	},
}

const actions = {
	getUser(context) {
		this.$http.get("/host/bmxt/userInfo.html")
		.then(result => {
			if(result.login){
				context.commit("setUser", result);
			}else{
				window.location.href =_config._WEB_SERVER + "/bmxt/#/login";
			}
		});
	},
	
	getAllCampus(context) {
		this.$http.get("/host/bmxt/getAllCampus.html")
		.then(cams => {
			context.commit("setCampus", cams);
		});
	},
	
	
	getdq(context) {
		this.$http.get("/host/bmxt/getArea.html")
		.then(result => {
			var towns=result;
			
			var dqs=new Array();
			for(var i=0;i<towns.length;i++){
				
				var village=towns[i].village;
				var childern=new Array();
				for(var j=0;j<village.length;j++){
					var child={
						value: village[j].VAID,
                        label: village[j].VANAME
					}
					childern.push(child);
				}
				
				var are={
                    value: towns[i].TNID,
                    label: towns[i].TNNAME,
                    children: childern
                }
				
				dqs.push(are);
			}
			
			context.commit("setAreas", result);
			context.commit("setdq", dqs);
		});
	},
	
	
	getnbz(context) {
		this.$http.get("/host/bmxt/getnbz.html")
		.then(result => {
			context.commit("setVillsnb", result);			
		});
	},
	
}

export default {
	state,
	mutations,
	actions
}